#!/usr/bin/env python

import re
import os


def Config(DeviceName,SortType,FileConfigPath,FileConfig):
    """Get Device configuration data"""
    
    Version=""
    Patch =""
    TestItemNum=""
    DigitalTestItemNum=""
    TestItenNames=""
    FlagConfig=False
    
    os.chdir(FileConfigPath)
    FileConfigFH=open(FileConfig)
    Lines = FileConfigFH.readlines()
    TempPattern="".join((DeviceName,":",SortType))
    for Line in Lines:
        if re.search("^#",Line,re.I):
            continue
        if re.search(TempPattern,Line,re.I) : 
            Line=Line.rstrip()
            TempArray=re.split(r":",Line)
            Version=TempArray[2]
            Patch=TempArray[3]
            TestItemNum=TempArray[4]
            DigitalTestItemNum=TempArray[5]
            TestItemNames=TempArray[6]
            FlagConfig=True
            break    
    if FlagConfig:
        return(FlagConfig,Version,Patch,TestItemNum,DigitalTestItemNum,TestItemNames)
    else:  
        
        return (FlagConfig,None,None,None,None,None)
    
def main():    
    
    Temp=Configure("HED0409","Sort1","configure")
        

if __name__ == '__main__':
    main()
